package com.mall.service.marketing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.model.domain.SmsFlashPromotion;
import com.mall.model.vo.PageResult;
import com.mall.service.marketing.mapper.SmsFlashPromotionMapper;
import com.mall.service.marketing.service.SmsFlashPromotionService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SmsFlashPromotionServiceImpl extends ServiceImpl<SmsFlashPromotionMapper, SmsFlashPromotion> implements SmsFlashPromotionService {

    @Autowired
    private SmsFlashPromotionMapper smsFlashPromotionMapper;

    /**
     * 根据活动名称分页查询
     *
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResult list(String keyword, Integer pageNum, Integer pageSize) {
        IPage<SmsFlashPromotion> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SmsFlashPromotion> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.like(StringUtils.isNotEmpty(keyword), SmsFlashPromotion::getTitle, keyword);

        IPage<SmsFlashPromotion> pageInfo = smsFlashPromotionMapper.selectPage(page, queryWrapper);
        return new PageResult(pageNum, pageSize, (int) pageInfo.getTotal(), pageInfo.getRecords());
    }
}
